﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using ZF.BLL;
using GCELibrary.Current;
namespace ZF.WS
{
    public partial class UpLoadFile : BLL.Page.PageBase
    {
        [PageArgument(Key = "type", CanNull = false)]
        public string Type { get; set; }


        protected void Page_Load(object sender, EventArgs e)
        {


            if (this.Type.EqIgnoreCase("house") || this.Type.EqIgnoreCase("news")
                || this.Type.EqIgnoreCase("shop") || this.Type.EqIgnoreCase("member")
                || this.Type.EqIgnoreCase("game") || this.Type.EqIgnoreCase("ads")
                || this.Type.EqIgnoreCase("service") || this.Type.EqIgnoreCase("info"))
            {
                if (Request.Files.Count > 0)
                {
                    // Get the data

                    HttpPostedFile jpeg_image_upload = Request.Files["Filedata"];
                    var fileTime = DateTime.Now.ToFileTime();
                    var lpath = Server.MapPath(string.Format("~/photo/{0}", this.Type));
                    if (!Directory.Exists(lpath))
                        Directory.CreateDirectory(lpath);

                    var fileType = Path.GetExtension(jpeg_image_upload.FileName);
                    string formatFileName = fileTime + fileType;
                    string saveFilePath = Path.Combine(lpath, formatFileName);
                    jpeg_image_upload.SaveAs(saveFilePath);
                    Response.StatusCode = 200;

                    Response.Write(formatFileName);
                    Response.End();
                }
            }
        }
    }

}
 
